package zee.com.customviewexample

import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.zee.bean.DateStyle
import com.zee.extendobject.runOnIOThread
import com.zee.extendobject.runOnMainThread
import com.zee.extendobject.setOnClickListenerEx
import com.zee.log.ZLog
import com.zee.utils.ZDateUtil
import com.zee.utils.ZEventBusUtils
import kotlinx.android.synthetic.main.activity_custom_view_main.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import zee.com.customviewexample.activity.*
import zee.com.customviewexample.activity.taglayout.ZxTagLayoutActivity
import zee.com.customviewexample.bean.TestPresenter
import java.util.*
import java.util.concurrent.atomic.AtomicLong

@SuppressWarnings("all")
class CustomViewMainActivity : AppCompatActivity() {
    private val mFragments = ArrayList<Fragment>()
    private val mTitles = arrayOf("ZXTextView", "ZXSolid", "ZXLinearLayout")


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        ZLog.i("当前时间:" + ZDateUtil.DateToString(Date(), DateStyle.YYYY_MM))

        setContentView(R.layout.activity_custom_view_main)
        ZLog.i(ZDateUtil.getCurDateString(DateStyle.MM_DD_HH_MM_CN))

        id_EditView.setOnClickListener {
            startActivity(ZxEditViewActivity::class.java)
        }

        tv_chait.setOnClickListener {
            //折线图
            startActivity(ChartMainActivity::class.java)
        }

        tv_snackBar.setOnClickListener {
            //SnackerBar的使用
            startActivity(SnackBarActivity::class.java)
        }

        tv_code_creat_view.setOnClickListener {
            //代码自动生成View
            startActivity(MyCustomViewActivity::class.java)
        }
        //浮动窗口
        runBlocking {
            launch {

            }
        }
        tv_flow_window.setOnClickListener {
            startActivity(MyFloatWindowActivity::class.java)
        }

        tv_imageView.setOnClickListener {
            startActivity(ZxRoundImageViewActivity::class.java)
        }
        //代码生成Shape
        tv_shape.setOnClickListener {
            startActivity(ZxShapeActivity::class.java)
        }

        //时间选择器
        tv_time_select.setOnClickListener {
            startActivity(ZxMyTimeDialogActivity::class.java)
        }

        id_ZxTextView.setOnClickListener {
            tv_time_select.isSelected = !tv_time_select.isSelected
        }

        id_password.setOnClickListener {
            startActivity(ZxPassWordViewActivity::class.java)
        }

        id_pop.setOnClickListenerEx(View.OnClickListener {
            startActivity(ZxPopupWindowActivity::class.java)
        })
        id_dialog.setOnClickListener {
            startActivity(MyDialogMainActivity::class.java)
        }

        id_FoldTextView.setOnClickListener {
            //折叠TextView
            startActivity(ZxFoldTextViewActivity::class.java)
        }

        id_bannerView.setOnClickListener {
            startActivity(ZxBannerActivity::class.java)
        }

        id_solidTabLayout.setOnClickListener {
            startActivity(ZxSolidTabLayoutActivity::class.java)
        }

        id_ZxTabLayout.setOnClickListener {
            startActivity(ZxTabLayoutActivity::class.java)
        }

        id_ZxTagLayout.setOnClickListener {
            startActivity(ZxTagLayoutActivity::class.java)
        }

        id_solidItemTabLayout.setOnClickListener {
            startActivity(ZxSolidItemTabLayoutActivity::class.java)
        }
        //RecyclerView数据
        id_ZxRecyclerView.setOnClickListener {
            startActivity(ZxRecyclerViewActivity::class.java)
        }
        id_ZxSwitch.setOnClickListener {
            startActivity(ZxSwitchViewActivity::class.java)
        }

        id_ZxFragment.setOnClickListener {
            startActivity(ZxBottomBarLayoutActivity::class.java)
        }

        TestPresenter.testListener(1, {})
        TestPresenter.testListener(100,
                {
                    ZLog.i("onNest------>>>>")
                },
                {
                    ZLog.i("onError------>>>>")
                })

    }

    /**
     * 启动activity
     */
    fun startActivity(clazz: Class<*>) {
        val intent = Intent(this, clazz)
        startActivity(intent)
    }

    override fun onDestroy() {
        super.onDestroy()
        ZEventBusUtils.unregister(this)
    }

    fun test() {


    }

}
